package com.itheima.case2.dao;

import com.itheima.case2.pojo.po.Permission;
import com.itheima.case2.pojo.vo.AddPermission;
import com.itheima.case2.pojo.vo.UpdatePermission;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PermissionMapper {
    //查询所有权限信息
    @Select("select * from t_permission")
    List<Permission> queryAllPermission();
    //查询权限表数据条数
    Long queryAllPermissionCount(@Param("name") String name);
    //分页查询权限以及角色信息
    List<Permission> queryPerAndRoleByPage(@Param("startIndex") Integer index, @Param("pageSize") Integer pageSize, @Param("name") String name);

    //修改权限信息
    @Update("update t_permission set name=#{name},keyword=#{keyword},description=#{description} where id=#{id}")
    void updatePermission(UpdatePermission updatePermission);
    //删除该权限对应的角色
    @Delete("delete from t_role_permission where permission_id=#{id}")
    void deleteById(@Param("id") String id);
    //添加该权限的角色信息
    @Insert("insert into t_role_permission values (#{roleId},#{perId})")
    void insertPerAndRole(@Param("roleId") String roleId,@Param("perId") String perId);

    //添加权限和对应的角色信息
    @Insert("insert into t_permission values(null,#{name},#{keyword},#{description})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insertPermission(AddPermission addPermission);
    //删除权限信息（需要先删除该角色权限中间表的所有和该权限有关信息）
    @Delete("delete from t_permission where id=#{id}")
    void deletePermission(@Param("id") String id);

}
